class EventEmitter {
    private events: { [key: string]: Function[] } = {};
    
    emit(event: string, ...args: any[]) {
      if (this.events[event]) {
          this.events[event].forEach((listener) => listener(...args));
      } else {
          console.warn(`Event ${event} does not exist`);
      }
    }

    on(event: string, listener: Function) {
      if (!this.events[event]) {
          this.events[event] = [];
      }
      this.events[event].push(listener);
    }

    once(event: string, listener: Function) {
      const onceListener = (...args: any[]) => {
          listener(...args);
          this.off(event, onceListener);
      };
      this.on(event, onceListener);
    }

    off(event: string, listener: Function) {
      if (!this.events[event]) return;
      if (this.events[event]) {
          this.events[event] = this.events[event].filter((l) => l !== listener);
      }
    }
}

export default new EventEmitter();
